home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / EnhanceMail.1.3 / Source / XFace.m < prev    next >
Encoding:
Text File  |  1996-03-24  |  42.5 KB  |  1,358 lines

  1. /* -*-C-*-
  2. *******************************************************************************
  3. *
  4. * File:         XFace.m
  5. * RCS:          $Header: /usr/local/lib/cvs/EnhanceMail/XFace.m,v 1.1.1.6 1996/03/25 15:15:04 cedman Exp $
  6. * Description:  
  7. * Author:       Carl Edman
  8. * Created:      Tue Oct 17 08:06:48 1995
  9. * Modified:     Mon Mar 25 09:57:27 1996 (Carl Edman) cedman@capitalist.princeton.edu
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       Experimental (Do Not Distribute)
  13. *
  14. * (C) Copyright 1995, but otherwise this file is perfect freeware.
  15. *
  16. *******************************************************************************
  17. */
  18.  
  19. #import "XFace.h"
  20. #import "MailApp.h"
  21. #import <setjmp.h>
  22.  
  23. /*
  24.  *  Compface - 48x48x1 image compression and decompression
  25.  *
  26.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  27.  *
  28.  *  Written 11th November 1989.
  29.  *
  30.  *  Permission is given to distribute these sources, as long as the
  31.  *  copyright messages are not removed, and no monies are exchanged. 
  32.  *
  33.  *  No responsibility is taken for any errors on inaccuracies inherent
  34.  *  either to the comments or the code of this program, but if reported
  35.  *  to me, then an attempt will be made to fix them.
  36.  */
  37.  
  38. #define EMBEDDED
  39.  
  40. /* need to know how many bits per hexadecimal digit for io */
  41. #define BITSPERDIG 4
  42. #ifndef EMBEDDED
  43. static char HexDigits[]="0123456789ABCDEF";
  44. #endif
  45.  
  46. /* define the face size - 48x48x1 */
  47. #define WIDTH 48
  48. #define HEIGHT WIDTH
  49.  
  50. /* total number of pixels and digits */
  51. #define PIXELS (WIDTH * HEIGHT)
  52. #define DIGITS (PIXELS / BITSPERDIG)
  53.  
  54. /* internal face representation - 1 char per pixel is faster */
  55. static char F[PIXELS];
  56.  
  57. /* output formatting word lengths and line lengths */
  58. #define DIGSPERWORD 4
  59. #define WORDSPERLINE (WIDTH / DIGSPERWORD / BITSPERDIG)
  60.  
  61. /* compressed output uses the full range of printable characters.
  62.  * in ascii these are in a contiguous block so we just need to know
  63.  * the first and last.  The total number of printables is needed too */
  64. #define FIRSTPRINT '!'
  65. #define LASTPRINT '~'
  66. #define NUMPRINTS (LASTPRINT - FIRSTPRINT + 1)
  67.  
  68. /* output line length for compressed data */
  69. #define MAXLINELEN 72
  70.  
  71. /* Portable, very large unsigned integer arithmetic is needed.
  72.  * Implementation uses arrays of WORDs.  COMPs must have at least
  73.  * twice as many bits as WORDs to handle intermediate results */
  74. #define WORD unsigned char
  75. #define COMP unsigned long
  76. #define BITSPERWORD 8
  77. #define WORDCARRY (1 << BITSPERWORD)
  78. #define WORDMASK (WORDCARRY - 1)
  79. #define MAXWORDS ((PIXELS * 2 + BITSPERWORD - 1) / BITSPERWORD)
  80.  
  81. typedef struct bigint
  82.    {
  83.    int b_words;
  84.    WORD b_word[MAXWORDS];
  85.    } BigInt;
  86.  
  87. static BigInt B;
  88.  
  89. /* This is the guess the next pixel table.  Normally there are 12 neighbour
  90.  * pixels used to give 1<<12 cases but in the upper left corner lesser
  91.  * numbers of neighbours are available, leading to 6231 different guesses */
  92. typedef struct guesses
  93.    {
  94.    char g_00[1<<12];
  95.    char g_01[1<<7];
  96.    char g_02[1<<2];
  97.    char g_10[1<<9];
  98.    char g_20[1<<6];
  99.    char g_30[1<<8];
  100.    char g_40[1<<10];
  101.    char g_11[1<<5];
  102.    char g_21[1<<3];
  103.    char g_31[1<<5];
  104.    char g_41[1<<6];
  105.    char g_12[1<<1];
  106.    char g_22[1<<0];
  107.    char g_32[1<<2];
  108.    char g_42[1<<2];
  109.    } Guesses;
  110.  
  111. /* data.h was established by sampling over 1000 faces and icons */
  112. static Guesses G =
  113.    {
  114.       {
  115.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
  117.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118.       1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  119.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1,
  120.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  121.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1,
  122.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  123.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
  124.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125.       0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  126.       0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  127.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  128.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  129.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1,
  130.       0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1,
  131.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  132.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,
  133.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
  134.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  135.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
  136.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
  137.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1,
  138.       1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  139.       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  140.       1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1,
  141.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  142.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  143.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  144.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  145.       0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  146.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  147.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0,
  148.       0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  149.       0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1,
  150.       1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1,
  151.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  152.       0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  153.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  154.       0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  155.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  156.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  157.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  158.       1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  159.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  160.       0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1,
  161.       0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  162.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  163.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  164.       0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  165.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  166.       1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  167.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  168.       0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  169.       1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  170.       1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
  171.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  172.       1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
  173.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  174.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  175.       0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
  176.       0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1,
  177.       0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  178.       1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  179.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  180.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
  181.       0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  182.       0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  183.       0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  184.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  185.       0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0,
  186.       0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  187.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  188.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  189.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  190.       0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1,
  191.       1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1,
  192.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
  193.       0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1,
  194.       0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
  195.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  196.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  197.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  198.       1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1,
  199.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1,
  200.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  201.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  202.       1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  203.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
  204.       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  205.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  206.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  207.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
  208.       0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  209.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  210.       1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1,
  211.       0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
  212.       0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  213.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
  214.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  215.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  216.       1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  217.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  218.       0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  219.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
  220.       1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  221.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  222.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  223.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  224.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  225.       1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1,
  226.       1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  227.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
  228.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  229.       0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  230.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  231.       0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  232.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  233.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  234.       1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  235.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
  236.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  237.       0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  238.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  239.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  240.       1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  241.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  242.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  243.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  244.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,
  245.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
  246.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  247.       0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  248.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
  249.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0,
  250.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  251.       0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
  252.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  253.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  254.       0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  255.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  256.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  257.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  258.       0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  259.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  260.       1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  261.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  262.       1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  263.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0,
  264.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,
  265.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1,
  266.       1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  267.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  268.       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  269.       0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  270.       0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0,
  271.       0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  272.       1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  273.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1,
  274.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  275.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  276.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  277.       0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  278.       1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  279.       0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0,
  280.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  281.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  282.       1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  283.       0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  284.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  285.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  286.       1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  287.       0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
  288.       0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1,
  289.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  290.       1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  291.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,
  292.       0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1,
  293.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  294.       1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1,
  295.       0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1,
  296.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  297.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  298.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  299.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1,
  300.       1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1,
  301.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  302.       1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  303.       0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  304.       1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,
  305.       0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  306.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  307.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
  308.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
  309.       0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1,
  310.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1,
  311.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
  312.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  313.       0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0,
  314.       0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  315.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  316.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  317.       0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  318.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  319.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  320.       1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
  321.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  322.       0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  323.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
  324.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  325.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1,
  326.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  327.       0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
  328.       0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  329.       0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  330.       1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  331.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  332.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  333.       0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
  334.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  335.       0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0,
  336.       1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1,
  337.       1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  338.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  339.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  340.       0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  341.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
  342.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  343.       0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1,
  344.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  345.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
  346.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  347.       0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0,
  348.       1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  349.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  350.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  351.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0,
  352.       1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  353.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  354.       1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  355.       0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0,
  356.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  357.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  358.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  359.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0,
  360.       1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  361.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  362.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  363.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,
  364.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  365.       0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  366.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  367.       0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0,
  368.       1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  369.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  370.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  371.     },
  372.     {
  373.       0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1,
  374.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,
  375.       0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  376.       1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
  377.       0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1,
  378.       1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,
  379.       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  380.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  381.       },
  382.       {
  383.       0, 1, 0, 1, 
  384.       },
  385.       {
  386.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  387.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  388.       0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  389.       1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
  390.       1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
  391.       0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 
  392.       0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 
  393.       0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  394.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  395.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
  396.       0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
  397.       0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 
  398.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
  399.       0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 
  400.       0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 
  401.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  402.       0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
  403.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
  404.       0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  405.       0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 
  406.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 
  407.       0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
  408.       0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 
  409.       1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  410.       0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 
  411.       0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 
  412.       0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 
  413.       1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 
  414.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
  415.       0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 
  416.       0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  417.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  418.       },
  419.       {
  420.       0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  421.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
  422.       0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 
  423.       1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 
  424.       },
  425.       {
  426.       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  427.       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  428.       0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  429.       0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  430.       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  431.       0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  432.       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  433.       0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  434.       0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  435.       0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
  436.       0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
  437.       0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 
  438.       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
  439.       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  440.       0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  441.       0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 
  442.       },
  443.       {
  444.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  445.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 
  446.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  447.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  448.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  449.       0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 
  450.       1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  451.       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  452.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  453.       0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 
  454.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 
  455.       0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 
  456.       1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 
  457.       0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  458.       1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  459.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  460.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 
  461.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  462.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
  463.       0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 
  464.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 
  465.       0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
  466.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 
  467.       0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 
  468.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  469.       0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
  470.       0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  471.       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  472.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  473.       0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
  474.       1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  475.       1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  476.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  477.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  478.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 
  479.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
  480.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
  481.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 
  482.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  483.       0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  484.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 
  485.       0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 
  486.       0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  487.       0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 
  488.       0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
  489.       0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  490.       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  491.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  492.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  493.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 
  494.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 
  495.       0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 
  496.       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 
  497.       0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  498.       0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 
  499.       0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 
  500.       0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  501.       0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
  502.       0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  503.       0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 
  504.       0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  505.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  506.       0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 
  507.       0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  508.       },
  509.       {
  510.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
  511.       0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  512.       },
  513.       {
  514.       0, 0, 0, 1, 0, 1, 1, 1, 
  515.       },
  516.       {
  517.       0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 
  518.       0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  519.       },
  520.       {
  521.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
  522.       0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
  523.       0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
  524.       0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  525.       },
  526.       {
  527.       0, 1, 
  528.       },
  529.       {
  530.       0, 
  531.       },
  532.       {
  533.       0, 0, 0, 1, 
  534.       },
  535.       {
  536.       0, 0, 0, 1, 
  537.       }
  538.    };
  539.  
  540. /* Data of varying probabilities are encoded by a value in the range 0 - 255.
  541.  * The probability of the data determines the range of possible encodings.
  542.  * Offset gives the first possible encoding of the range */
  543. typedef struct prob
  544.    {
  545.    WORD p_range;
  546.    WORD p_offset;
  547.    } Prob;
  548.  
  549. /* A stack of probability values */
  550. static Prob *ProbBuf[PIXELS * 2];
  551. static int NumProbs=0;
  552.  
  553. /* Each face is encoded using 9 octrees of 16x16 each.  Each level of the
  554.  * trees has varying probabilities of being white, grey or black.
  555.  * The table below is based on sampling many faces */
  556.  
  557. #define BLACK 0
  558. #define GREY 1
  559. #define WHITE 2
  560.  
  561. static Prob levels[4][3] =
  562.    {
  563.       {{  1, 255}, {251,   0}, {   4, 251}}, /* Top of tree almost always grey */
  564.       {{  1, 255}, {200,   0}, {  55, 200}},
  565.       {{ 33, 223}, {159,   0}, {  64, 159}},
  566.       {{131,   0}, {  0,   0}, { 125, 131}}  /* Grey disallowed at bottom */
  567.    };
  568.  
  569. /* At the bottom of the octree 2x2 elements are considered black if any
  570.  * pixel is black.  The probabilities below give the distribution of the
  571.  * 16 possible 2x2 patterns.  All white is not really a possibility and
  572.  * has a probability range of zero.  Again, experimentally derived data */
  573. static Prob freqs[16] =
  574.    {
  575.       {0, 0}, {38, 0}, {38, 38}, {13, 152}, {38, 76}, {13, 165}, {13, 178},
  576.       {6, 230}, {38, 114}, {13, 191}, {13, 204}, {6, 236}, {13, 217},
  577.       {6, 242}, {5, 248}, {3, 253}
  578.    };
  579.  
  580. /* successful completion */
  581. #define ERR_OK          0
  582. /* completed OK but some input was ignored */
  583. #define ERR_EXCESS      1
  584. /* insufficient input.  Bad face format? */
  585. #define ERR_INSUFF     -1
  586. /* Arithmetic overflow or buffer overflow */
  587. #define ERR_INTERNAL   -2
  588.  
  589. #define GEN(g) F[h] ^= G.g[k]; break
  590.  
  591. static jmp_buf comp_env;
  592. #ifndef EMBEDDED
  593. static int status;
  594. #endif
  595.  
  596. static int AllBlack(char *, int, int);
  597. static int AllWhite(char *, int, int);
  598. static int BigPop(Prob *);
  599. static int Same(char *, int, int);
  600.  
  601. static void BigAdd(unsigned char);
  602. static void BigClear(void);
  603. static void BigDiv(unsigned char, unsigned char *);
  604. static void BigMul(unsigned char);
  605. static void BigPush(Prob *);
  606. static void BigRead(const char *);
  607. static void BigWrite(char *);
  608. static void CompAll(char *);
  609. static void Compress(char *, int, int, int);
  610. static void Gen(char *);
  611. static void GenFace(void);
  612. static void PopGreys(char *, int, int);
  613. static void PushGreys(char *, int, int);
  614. static void RevPush(Prob *);
  615. static void UnCompAll(const char *);
  616. static void UnCompress(char *, int, int, int);
  617. static void UnGenFace(void);
  618. #ifndef EMBEDDED
  619. static void BigPrint(void);
  620. static void BigSub(unsigned char);
  621. static void ReadFace(char *);
  622. static void WriteFace(char *);
  623. #endif
  624.  
  625. static void RevPush(Prob *p)
  626.    {
  627.    if (NumProbs >= PIXELS * 2 - 1)
  628.       longjmp(comp_env, ERR_INTERNAL);
  629.    ProbBuf[NumProbs++] = p;
  630.    }
  631.  
  632. static void BigPush(Prob *p)
  633.    {
  634.    static WORD tmp;
  635.    
  636.    BigDiv(p->p_range, &tmp);
  637.    BigMul(0);
  638.    BigAdd(tmp + p->p_offset);
  639.    }
  640.  
  641. static int BigPop(Prob *p)
  642.    {
  643.    static WORD tmp;
  644.    int i;
  645.    
  646.    BigDiv(0, &tmp);
  647.    i = 0;
  648.    while ((tmp < p->p_offset) || (tmp >= p->p_range + p->p_offset))
  649.       {
  650.       p++;
  651.       i++;
  652.       }
  653.    BigMul(p->p_range);
  654.    BigAdd(tmp - p->p_offset);
  655.    return i;
  656.    }
  657.  
  658. #ifndef EMBEDDED
  659. /* Print a BigInt in HexaDecimal */
  660. static void BigPrint(void)
  661.    {
  662.    int i, c, count;
  663.    WORD *w;
  664.  
  665.    count = 0;
  666.    w = B.b_word + (i = B.b_words);
  667.    while (i--)
  668.       {
  669.       w--;
  670.       c = *((*w >> 4) + HexDigits);
  671.       putc(c, stderr);
  672.       c = *((*w & 0xf) + HexDigits);
  673.       putc(c, stderr);
  674.       if (++count >= 36)
  675.          {
  676.          putc('\\', stderr);
  677.          putc('\n', stderr);
  678.          count = 0;
  679.          }
  680.       }
  681.    putc('\n', stderr);
  682.    }
  683. #endif
  684.  
  685. /* Divide B by a storing the result in B and the remainder in the word
  686.  * pointer to by r */
  687. static void BigDiv(WORD a, WORD *r)
  688.    {
  689.    int i;
  690.    WORD *w;
  691.    COMP c, d;
  692.  
  693.    a &= WORDMASK;
  694.    if ((a == 1) || (B.b_words == 0))
  695.       {
  696.       *r = 0;
  697.       return;
  698.       }
  699.    if (a == 0)    /* treat this as a == WORDCARRY */
  700.       {            /* and just shift everything right a WORD */
  701.       i = --B.b_words;
  702.       w = B.b_word;
  703.       *r = *w;
  704.       while (i--)
  705.          {
  706.          *w = *(w + 1);
  707.          w++;
  708.          }
  709.       *w = 0;
  710.       return;
  711.       }
  712.    w = B.b_word + (i = B.b_words);
  713.    c = 0;
  714.    while (i--)
  715.       {
  716.       c <<= BITSPERWORD;
  717.       c += (COMP)*--w;
  718.       d = c / (COMP)a;
  719.       c = c % (COMP)a;
  720.       *w = (WORD)(d & WORDMASK);
  721.       }
  722.    *r = c;
  723.    if (B.b_word[B.b_words - 1] == 0)
  724.       B.b_words--;
  725.    }
  726.  
  727. /* Multiply a by B storing the result in B */
  728. static void BigMul(WORD a)
  729.    {
  730.    int i;
  731.    WORD *w;
  732.    COMP c;
  733.    
  734.    a &= WORDMASK;
  735.    if ((a == 1) || (B.b_words == 0))
  736.       return;
  737.    if (a == 0)    /* treat this as a == WORDCARRY */
  738.       {            /* and just shift everything left a WORD */
  739.       if ((i = B.b_words++) >= MAXWORDS - 1)
  740.          longjmp(comp_env, ERR_INTERNAL);
  741.       w = B.b_word + i;
  742.       while (i--)
  743.          {
  744.          *w = *(w - 1);
  745.          w--;
  746.          }
  747.       *w = 0;
  748.       return;
  749.       }
  750.    i = B.b_words;
  751.    w = B.b_word;
  752.    c = 0;
  753.    while (i--)
  754.       {
  755.       c += (COMP)*w * (COMP)a;
  756.       *(w++) = (WORD)(c & WORDMASK);
  757.       c >>= BITSPERWORD;
  758.       }
  759.    if (c)
  760.       {
  761.       if (B.b_words++ >= MAXWORDS)
  762.          longjmp(comp_env, ERR_INTERNAL);
  763.       *w = (COMP)(c & WORDMASK);
  764.       }
  765.    }
  766.  
  767. #ifndef EMBEDDED
  768. /* Subtract a from B storing the result in B */
  769. static void BigSub(WORD a)
  770.    {
  771.    int i;
  772.    WORD *w;
  773.    COMP c;
  774.    
  775.    a &= WORDMASK;
  776.    if (a == 0)
  777.       return;
  778.    i = 1;
  779.    w = B.b_word;
  780.    c = (COMP)*w - (COMP)a;
  781.    *w = (WORD)(c & WORDMASK);
  782.    while (c & WORDCARRY)
  783.       {
  784.       if (i >= B.b_words)
  785.          longjmp(comp_env, ERR_INTERNAL);
  786.       c = (COMP)*++w - 1;
  787.       *w = (WORD)(c & WORDMASK);
  788.       i++;
  789.       }
  790.    if ((i == B.b_words) && (*w == 0) && (i > 0))
  791.       B.b_words--;
  792.    }
  793. #endif
  794.  
  795. /* Add to a to B storing the result in B */
  796. static void BigAdd(WORD a)
  797.    {
  798.    int i;
  799.    WORD *w;
  800.    COMP c;
  801.    
  802.    a &= WORDMASK;
  803.    if (a == 0)
  804.       return;
  805.    i = 0;
  806.    w = B.b_word;
  807.    c = a;
  808.    while ((i < B.b_words) && c)
  809.       {
  810.       c += (COMP)*w;
  811.       *w++ = (WORD)(c & WORDMASK);
  812.       c >>= BITSPERWORD;
  813.       i++;
  814.       }
  815.    if ((i == B.b_words) && c)
  816.       {
  817.       if (B.b_words++ >= MAXWORDS)
  818.          longjmp(comp_env, ERR_INTERNAL);
  819.       *w = (COMP)(c & WORDMASK);
  820.       }
  821.    }
  822.  
  823. static void BigClear(void)
  824.    {
  825.    B.b_words = 0;
  826.    }
  827.  
  828. static int Same(char *f, int wid, int hei)
  829.    {
  830.    char val, *row;
  831.    int x;
  832.    
  833.    val = *f;
  834.    while (hei--)
  835.       {
  836.       row = f;
  837.       x = wid;
  838.       while (x--)
  839.          if (*(row++) != val)
  840.             return(0);
  841.       f += WIDTH;
  842.       }
  843.    return 1;
  844.    }
  845.  
  846. static int AllBlack(char *f, int wid, int hei)
  847.    {
  848.    if (wid > 3)
  849.       {
  850.       wid /= 2;
  851.       hei /= 2;
  852.       return (AllBlack(f, wid, hei) && AllBlack(f + wid, wid, hei) &&
  853.               AllBlack(f + WIDTH * hei, wid, hei) &&
  854.               AllBlack(f + WIDTH * hei + wid, wid, hei));
  855.       }
  856.    else
  857.       return (*f || *(f + 1) || *(f + WIDTH) || *(f + WIDTH + 1));
  858.    }
  859.  
  860. static int AllWhite(char *f, int wid, int hei)
  861.    {
  862.    return ((*f == 0) && Same(f, wid, hei));
  863.    }
  864.  
  865. static void PopGreys(char *f, int wid, int hei)
  866.    {
  867.    if (wid > 3)
  868.       {
  869.       wid /= 2;
  870.       hei /= 2;
  871.       PopGreys(f, wid, hei);
  872.       PopGreys(f + wid, wid, hei);
  873.       PopGreys(f + WIDTH * hei, wid, hei);
  874.       PopGreys(f + WIDTH * hei + wid, wid, hei);
  875.       }
  876.    else
  877.       {
  878.       wid = BigPop(freqs);
  879.       if (wid & 1)
  880.          *f = 1;
  881.       if (wid & 2)
  882.          *(f + 1) = 1;
  883.       if (wid & 4)
  884.          *(f + WIDTH) = 1;
  885.       if (wid & 8)
  886.          *(f + WIDTH + 1) = 1;
  887.       }
  888.    }
  889.  
  890. static void PushGreys(char *f, int wid, int hei)
  891.    {
  892.    if (wid > 3)
  893.       {
  894.       wid /= 2;
  895.       hei /= 2;
  896.       PushGreys(f, wid, hei);
  897.       PushGreys(f + wid, wid, hei);
  898.       PushGreys(f + WIDTH * hei, wid, hei);
  899.       PushGreys(f + WIDTH * hei + wid, wid, hei);
  900.       }
  901.    else
  902.       RevPush(freqs + *f + 2 * *(f + 1) + 4 * *(f + WIDTH) +
  903.               8 * *(f + WIDTH + 1));
  904.    }
  905.  
  906. static void UnCompress(char *f, int wid, int hei, int lev)
  907.    {
  908.    switch (BigPop(&levels[lev][0]))
  909.       {
  910.     case WHITE :
  911.        return;
  912.      case BLACK :
  913.         PopGreys(f, wid, hei);
  914.        return;
  915.      default :
  916.         wid /= 2;
  917.        hei /= 2;
  918.        lev++;
  919.        UnCompress(f, wid, hei, lev);
  920.        UnCompress(f + wid, wid, hei, lev);
  921.        UnCompress(f + hei * WIDTH, wid, hei, lev);
  922.        UnCompress(f + wid + hei * WIDTH, wid, hei, lev);
  923.        return;
  924.        }
  925.    }
  926.  
  927. static void Compress(char *f, int wid, int hei, int lev)
  928.    {
  929.    if (AllWhite(f, wid, hei))
  930.       {
  931.       RevPush(&levels[lev][WHITE]);
  932.       return;
  933.       }
  934.    if (AllBlack(f, wid, hei))
  935.       {
  936.       RevPush(&levels[lev][BLACK]);
  937.       PushGreys(f, wid, hei);
  938.       return;
  939.       }
  940.    RevPush(&levels[lev][GREY]);
  941.    wid /= 2;
  942.    hei /= 2;
  943.    lev++;
  944.    Compress(f, wid, hei, lev);
  945.    Compress(f + wid, wid, hei, lev);
  946.    Compress(f + hei * WIDTH, wid, hei, lev);
  947.    Compress(f + wid + hei * WIDTH, wid, hei, lev);
  948.    }
  949.  
  950. static void UnCompAll(const char *fbuf)
  951.    {
  952.    char *p;
  953.    
  954.    BigClear();
  955.    BigRead(fbuf);
  956.    p = F;
  957.    while (p < F + PIXELS)
  958.       *(p++) = 0;
  959.    UnCompress(F, 16, 16, 0);
  960.    UnCompress(F + 16, 16, 16, 0);
  961.    UnCompress(F + 32, 16, 16, 0);
  962.    UnCompress(F + WIDTH * 16, 16, 16, 0);
  963.    UnCompress(F + WIDTH * 16 + 16, 16, 16, 0);
  964.    UnCompress(F + WIDTH * 16 + 32, 16, 16, 0);
  965.    UnCompress(F + WIDTH * 32, 16, 16, 0);
  966.    UnCompress(F + WIDTH * 32 + 16, 16, 16, 0);
  967.    UnCompress(F + WIDTH * 32 + 32, 16, 16, 0);
  968.    }
  969.  
  970. static void CompAll(char *fbuf)
  971.    {
  972.    Compress(F, 16, 16, 0);
  973.    Compress(F + 16, 16, 16, 0);
  974.    Compress(F + 32, 16, 16, 0);
  975.    Compress(F + WIDTH * 16, 16, 16, 0);
  976.    Compress(F + WIDTH * 16 + 16, 16, 16, 0);
  977.    Compress(F + WIDTH * 16 + 32, 16, 16, 0);
  978.    Compress(F + WIDTH * 32, 16, 16, 0);
  979.    Compress(F + WIDTH * 32 + 16, 16, 16, 0);
  980.    Compress(F + WIDTH * 32 + 32, 16, 16, 0);
  981.    BigClear();
  982.    while (NumProbs > 0)
  983.       BigPush(ProbBuf[--NumProbs]);
  984.    BigWrite(fbuf);
  985.    }
  986.  
  987. static void BigRead(const char *fbuf)
  988.    {
  989.    int c;
  990.    
  991.    while ((c=*fbuf++) != '\0')
  992.       {
  993.       if ((c < FIRSTPRINT) || (c > LASTPRINT)) continue;
  994.       BigMul(NUMPRINTS);
  995.       BigAdd((WORD)(c - FIRSTPRINT));
  996.       }
  997.    }
  998.  
  999. static void BigWrite(char *fbuf)
  1000.    {
  1001.    static WORD tmp;
  1002.    static char buf[DIGITS];
  1003.    char *s = buf;
  1004.    int pos;
  1005.    
  1006.    while (B.b_words > 0)
  1007.       {
  1008.       BigDiv(NUMPRINTS, &tmp);
  1009.       *(s++) = tmp + FIRSTPRINT;
  1010.       }
  1011.  
  1012.    pos=0;
  1013.    while (s-- > buf)
  1014.       {
  1015.       *fbuf++=*s;
  1016.       pos++;
  1017.       if (pos==MAXLINELEN)
  1018.          {
  1019.          *fbuf++='\n';
  1020.          *fbuf++=' ';
  1021.          pos=0;
  1022.          }
  1023.       }
  1024.    *fbuf++='\0';
  1025.    }
  1026.  
  1027. #ifndef EMBEDDED
  1028. static void ReadFace(char *fbuf)
  1029.    {
  1030.    int c, i;
  1031.    char *s, *t;
  1032.    
  1033.    t = s = fbuf;
  1034.    for(i = strlen(s); i > 0; i--)
  1035.       {
  1036.       c = (int)*(s++);
  1037.       if ((c >= '0') && (c <= '9'))
  1038.          {
  1039.          if (t >= fbuf + DIGITS)
  1040.             {
  1041.             status = ERR_EXCESS;
  1042.             break;
  1043.             }
  1044.          *(t++) = c - '0';
  1045.          }
  1046.       else if ((c >= 'A') && (c <= 'F'))
  1047.          {
  1048.          if (t >= fbuf + DIGITS)
  1049.             {
  1050.             status = ERR_EXCESS;
  1051.             break;
  1052.             }
  1053.          *(t++) = c - 'A' + 10;
  1054.          }
  1055.       else if ((c >= 'a') && (c <= 'f'))
  1056.          {
  1057.          if (t >= fbuf + DIGITS)
  1058.             {
  1059.             status = ERR_EXCESS;
  1060.             break;
  1061.             }
  1062.          *(t++) = c - 'a' + 10;
  1063.          }
  1064.       else if (((c == 'x') || (c == 'X')) && (t > fbuf) && (*(t-1) == 0))
  1065.          t--;
  1066.       }
  1067.    if (t < fbuf + DIGITS)
  1068.       longjmp(comp_env, ERR_INSUFF);
  1069.    s = fbuf;
  1070.    t = F;
  1071.    c = 1 << (BITSPERDIG - 1);
  1072.    while (t < F + PIXELS)
  1073.       {
  1074.       *(t++) = (*s & c) ? 1 : 0;
  1075.       if ((c >>= 1) == 0)
  1076.          {
  1077.          s++;
  1078.          c = 1 << (BITSPERDIG - 1);
  1079.          }
  1080.       }
  1081.    }
  1082.  
  1083. static void WriteFace(char *fbuf)
  1084.    {
  1085.    char *s, *t;
  1086.    int i, bits, digits, words;
  1087.    
  1088.    s = F;
  1089.    t = fbuf;
  1090.    bits = digits = words = i = 0;
  1091.    while (s < F + PIXELS)
  1092.       {
  1093.       if ((bits == 0) && (digits == 0))
  1094.          {
  1095.          *(t++) = '0';
  1096.          *(t++) = 'x';
  1097.          }
  1098.       if (*(s++))
  1099.          i = i * 2 + 1;
  1100.       else
  1101.          i *= 2;
  1102.       if (++bits == BITSPERDIG)
  1103.          {
  1104.          *(t++) = *(i + HexDigits);
  1105.          bits = i = 0;
  1106.          if (++digits == DIGSPERWORD)
  1107.             {
  1108.             *(t++) = ',';
  1109.             digits = 0;
  1110.             if (++words == WORDSPERLINE)
  1111.                {
  1112.                *(t++) = '\n';
  1113.                words = 0;
  1114.                }
  1115.             }
  1116.          }
  1117.       }
  1118.    *(t++) = '\0';
  1119.    }
  1120. #endif
  1121.  
  1122. static void Gen(char *f)
  1123.    {
  1124.    int m, l, k, j, i, h;
  1125.    
  1126.    for (j = 0; j < HEIGHT;  j++)
  1127.       {
  1128.       for (i = 0; i < WIDTH;  i++)
  1129.          {
  1130.          h = i + j * WIDTH;
  1131.          k = 0;
  1132.          for (l = i - 2; l <= i + 2; l++)
  1133.             for (m = j - 2; m <= j; m++)
  1134.                {
  1135.                if ((l >= i) && (m == j))
  1136.                   continue;
  1137.                if ((l > 0) && (l <= WIDTH) && (m > 0))
  1138.                   k = *(f + l + m * WIDTH) ? k * 2 + 1 : k * 2;
  1139.                }
  1140.          switch (i)
  1141.             {
  1142.           case 1 :
  1143.              switch (j)
  1144.                 {
  1145.               case 1 : GEN(g_22);
  1146.               case 2 : GEN(g_21);
  1147.               default : GEN(g_20);
  1148.                 }
  1149.              break;
  1150.            case 2 :
  1151.               switch (j)
  1152.                  {
  1153.                case 1 : GEN(g_12);
  1154.                case 2 : GEN(g_11);
  1155.                default : GEN(g_10);
  1156.                  }
  1157.              break;
  1158.            case WIDTH - 1 :
  1159.               switch (j)
  1160.                  {
  1161.                case 1 : GEN(g_42);
  1162.                case 2 : GEN(g_41);
  1163.                default : GEN(g_40);
  1164.                  }
  1165.              break;
  1166.            case WIDTH :
  1167.               switch (j)
  1168.                  {
  1169.                case 1 : GEN(g_32);
  1170.                case 2 : GEN(g_31);
  1171.                default : GEN(g_30);
  1172.                  }
  1173.              break;
  1174.            default :
  1175.               switch (j)
  1176.                  {
  1177.                case 1 : GEN(g_02);
  1178.                case 2 : GEN(g_01);
  1179.                default : GEN(g_00);
  1180.                  }
  1181.              break;
  1182.              }
  1183.          }
  1184.       }
  1185.    }
  1186.  
  1187. static void GenFace(void)
  1188.    {
  1189.    static char new[PIXELS];
  1190.    char *f1;
  1191.    char *f2;
  1192.    int i;
  1193.    
  1194.    f1 = new;
  1195.    f2 = F;
  1196.    i = PIXELS;
  1197.    while (i-- > 0)
  1198.       *(f1++) = *(f2++);
  1199.    Gen(new);
  1200.    }
  1201.  
  1202. static void UnGenFace(void)
  1203.    {
  1204.    Gen(F);
  1205.    }
  1206.  
  1207. @implementation NXImage(XFace)
  1208. - initXFace:(const char *)xface size:(const NXSize *)size
  1209.    {
  1210.    int x,y,avg;
  1211.    int basex,basey;
  1212.    unsigned char *data;
  1213.    NXBitmapImageRep *bitrep;
  1214.  
  1215.    [self initSize:size];
  1216.  
  1217.    switch (setjmp(comp_env))
  1218.       {
  1219.     case ERR_INSUFF:   /* insufficient input.  Bad face format? */
  1220.       [self logError:"Insufficient input decoding X face."];
  1221.       return nil;
  1222.     case ERR_INTERNAL: /* Arithmetic overflow or buffer overflow */
  1223.       [self logError:"Internal error in decoding X face."];
  1224.       return nil;
  1225.     case ERR_EXCESS:   /* completed OK but some input was ignored */
  1226.       [self logWarning:"Excessive data in X face string ignored."];
  1227.     case ERR_OK:       /* successful completion */
  1228.     default:
  1229.       break;
  1230.       }
  1231.    
  1232.    UnCompAll(xface);
  1233.    UnGenFace();
  1234.  
  1235.    bitrep=[[NXBitmapImageRep alloc] initData:0 pixelsWide:size->width pixelsHigh:size->height bitsPerSample:1 samplesPerPixel:1 hasAlpha:NO isPlanar:YES colorSpace:NX_OneIsBlackColorSpace bytesPerRow:0 bitsPerPixel:0];
  1236.    data=[bitrep data];
  1237.  
  1238.    basex=(size->width-WIDTH)/2;
  1239.    basey=(size->height-HEIGHT)/2;
  1240.  
  1241.    /* This double counts the corners, but that is ok, right ?
  1242.       In a heuristic anyway */
  1243.    avg=0;
  1244.    for(x=0;x<WIDTH;x++)  avg += F[0*WIDTH+x] + F[(HEIGHT-1)*WIDTH+x];
  1245.    for(y=0;y<HEIGHT;y++) avg += F[y*WIDTH+0] + F[y*WIDTH+(WIDTH-1)];
  1246.    avg=(avg > (WIDTH+HEIGHT));
  1247.    
  1248.    for(y=0;y<size->height;y++) for(x=0;x<size->width;x++)
  1249.       {
  1250.       int pos=x+y*size->width;
  1251.       
  1252.       if (((x>=basex) && (x<basex+WIDTH) && (y>=basey) && (y<basey+HEIGHT)) ?
  1253.           F[(y-basey)*WIDTH+(x-basex)] : avg)
  1254.          data[pos/8] |= 1<<(7-pos%8);
  1255.       else
  1256.          data[pos/8] &= ~(1<<(7-pos%8));
  1257.       }
  1258.  
  1259.    if (![self useRepresentation:bitrep])
  1260.       {
  1261.       bitrep=[bitrep free];
  1262.       return nil;
  1263.       }
  1264.    
  1265.    return self;
  1266.    }
  1267.  
  1268. - initXFace:(const char *)xface
  1269.    {
  1270.    NXSize s;
  1271.    s.width=WIDTH;
  1272.    s.height=HEIGHT;
  1273.    return [self initXFace:xface size:&s];
  1274.    }
  1275.  
  1276. - (char *)xFace
  1277.    {
  1278.    id list=[self representationList];
  1279.    int x,y;
  1280.    char *face;   
  1281.    NXBitmapImageRep *bitrep=nil;
  1282.    int bpp=0,width=0,height=0;
  1283.    unsigned char *data=0;
  1284.    NXColorSpace space=NX_CustomColorSpace;
  1285.  
  1286.    for(x=[list count]-1;x>=0;x--)
  1287.       {
  1288.       bitrep=[list objectAt:x];
  1289.  
  1290.       if (bitrep==nil) continue;
  1291.       if (![bitrep isKindOf:[NXBitmapImageRep class]]) continue;
  1292.       
  1293.       space=[bitrep colorSpace];
  1294.       bpp=[bitrep bitsPerPixel];
  1295.       data=[bitrep data];
  1296.       width=[bitrep pixelsWide];
  1297.       height=[bitrep pixelsHigh];
  1298.       
  1299.       if (((space==NX_OneIsBlackColorSpace)||(space==NX_OneIsWhiteColorSpace))
  1300.           && (width==WIDTH) && (height==HEIGHT))
  1301.          break;
  1302.       else
  1303.          bitrep=nil;
  1304.       }
  1305.  
  1306.    if (bitrep==nil)
  1307.       {
  1308.       [self logWarning:"No valid X face representation in image."];
  1309.       return 0;
  1310.       }
  1311.    
  1312.    for(y=0;y<HEIGHT;y++) for(x=0;x<WIDTH;x++)
  1313.       {
  1314.       int pos=(x+y*width)*bpp;
  1315.  
  1316.       F[x+y*WIDTH]=(data[pos/8]>>(7-pos%8))&1;
  1317.       if (space==NX_OneIsWhiteColorSpace)
  1318.          F[x+y*WIDTH]=!F[x+y*WIDTH];
  1319.       }
  1320.  
  1321.    switch (setjmp(comp_env))
  1322.       {
  1323.     case ERR_INSUFF:   /* insufficient input.  Bad face format? */
  1324.       [self logError:"Insufficient input encoding X face."];
  1325.       return 0;
  1326.     case ERR_INTERNAL: /* Arithmetic overflow or buffer overflow */
  1327.       [self logError:"Internal error in encoding X face."];
  1328.       return 0;
  1329.     case ERR_EXCESS:   /* completed OK but some input was ignored */
  1330.       [self logWarning:"Excessive data in X face string ignored."];
  1331.     case ERR_OK:       /* successful completion */
  1332.     default:
  1333.       break;
  1334.       }
  1335.    
  1336.    GenFace();
  1337.    face=malloc(DIGITS+DIGITS/MAXLINELEN*2+1);
  1338.    CompAll(face);
  1339.    return face;
  1340.    }
  1341.  
  1342. - initFromFile:(const char *)filename xFaceSize:(const NXSize *)s
  1343.    {
  1344.    id image;
  1345.    char *face;
  1346.  
  1347.    image=[[NXImage alloc] init];
  1348.    if (image==nil) return [self free];
  1349.    if ([image loadFromFile:filename]==NO) return [image free],[self free];
  1350.    face=[image xFace];
  1351.    image=[image free];
  1352.    if (face==0) return [self free];
  1353.    image=[self initXFace:face size:s];
  1354.    free(face);
  1355.    return image;
  1356.    }
  1357. @end
  1358.